package com.zlict.admin.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zlict.common.annotation.Log;
import com.zlict.common.core.controller.BaseController;
import com.zlict.common.core.domain.AjaxResult;
import com.zlict.common.enums.BusinessType;
import com.zlict.admin.domain.UserSalary;
import com.zlict.admin.service.IUserSalaryService;
import com.zlict.common.utils.poi.ExcelUtil;
import com.zlict.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 研发人员工资Controller
 * 
 * @author ruoyi
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/system/salary")
public class UserSalaryController extends BaseController
{
    @Autowired
    private IUserSalaryService userSalaryService;

    /**
     * 查询研发人员工资列表
     */
    //@PreAuthorize("@ss.hasPermi('system:salary:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserSalary userSalary)
    {
        startPage();
        List<UserSalary> list = userSalaryService.selectUserSalaryList(userSalary);
        return getDataTable(list);

    }

    /**
     * 导出研发人员工资列表
     */
    //@PreAuthorize("@ss.hasPermi('system:salary:export')")
    @Log(title = "研发人员工资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody  UserSalary userSalary)
    {
        List<UserSalary> list = userSalaryService.selectUserSalaryList(userSalary);
        ExcelUtil<UserSalary> util = new ExcelUtil<UserSalary>(UserSalary.class);
        util.exportExcel(response, list, "研发人员工资数据");
    }

    /**
     * 获取研发人员工资详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:salary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userSalaryService.selectUserSalaryById(id));
    }

    /**
     * 新增研发人员工资
     */
    //@PreAuthorize("@ss.hasPermi('system:salary:add')")
    @Log(title = "研发人员工资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserSalary userSalary)
    {
        return toAjax(userSalaryService.insertUserSalary(userSalary));
    }

    /**
     * 修改研发人员工资
     */
    //@PreAuthorize("@ss.hasPermi('system:salary:edit')")
    @Log(title = "研发人员工资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserSalary userSalary)
    {
        return toAjax(userSalaryService.updateUserSalary(userSalary));
    }

    /**
     * 删除研发人员工资
     */
    //@PreAuthorize("@ss.hasPermi('system:salary:remove')")
    @Log(title = "研发人员工资", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userSalaryService.deleteUserSalaryByIds(ids));
    }


    /**
     * 导入模板下载
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<UserSalary> util = new ExcelUtil<UserSalary>(UserSalary.class);
        util.importTemplateExcel(response, "研发人员工资数据");
    }


    /**
     * 导入数据
     */
    //@PreAuthorize("@ss.hasPermi('system:salary:import')")
    @Log(title = "研发人员工资", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<UserSalary> util = new ExcelUtil<UserSalary>(UserSalary.class);
        List<UserSalary> salaryList = util.importExcel(file.getInputStream());
        Map<String,Object> map = userSalaryService.importSalary(salaryList, updateSupport);
        return success(map);
    }

}

